package com.ailk.tcm.hffw.android.common.ui.pagerAdapter;

import java.util.List;

import android.support.v4.view.PagerAdapter;
import android.view.View;
import android.view.ViewGroup;

public class ViewPagerAdapter extends PagerAdapter{
	private List<? extends View> views;
	private List<CharSequence> titles;

	public ViewPagerAdapter(List<? extends View> views, List<CharSequence> titles) {
		super();
		this.views = views;
		this.titles = titles;
	}

	@Override
	public Object instantiateItem(ViewGroup container, int position) {
		View item = views.get(position);
		container.addView(item);
		return item;
	}

	@Override
	public void destroyItem(ViewGroup container, int position, Object object) {
		container.removeView((View) object);
	}

	@Override
	public int getCount() {
		return views.size();
	}

	@Override
	public CharSequence getPageTitle(int position) {
		if(titles != null){
			return titles.get(position);
		}
		return super.getPageTitle(position);
	}

	@Override
	public boolean isViewFromObject(View arg0, Object arg1) {
		return arg0 == arg1;
	}
}
